/*
 *  SymbolTable.h
 *  Compiler
 *
 *  Created by Jacopo De Stefani on 3/5/12.
 *  Copyright 2012 Politecnico di Milano. All rights reserved.
 *
 */

#ifndef EXTENDEDSYMBOLTABLE_H
#define EXTENDEDSYMBOLTABLE_H

#include "SymbolTableAttributes.h"
#include <string>
#include <queue>
#include <map>

using namespace std;

//User types definition
typedef pair < string,SymbolTableAttributes > SymbolTableEntry;
typedef pair < string,queue<TypesP> > FunctionTableEntry;
typedef map < string,SymbolTableAttributes > SymbolTable; 
typedef map < string,queue<TypesP> > FunctionTable;

class ExtendedSymbolTable
{
public:
	ExtendedSymbolTable();
	
	//Adds a new entry in the table with default values and identifier id.
	void addSymbolTableEntry(string identifier);
	
	//Adds a new entry in the table with default values and identifier id.
	void addFunctionTableEntry(string identifier);
	
	//Updates the attributes of a list of variables using currVarList.
	void updateSymbolTable(TypesP type,ScopesP scope);
	
	//Updates the parameters' list for a given function using currTypeList;
	void updateTypeList(string identifier);
						   
	//Modifiers of the list of variables
	void pushVar(string varId);
	void flushVarList();
	
	//Modifiers of the list of parameters
	void pushType(TypesP paramType);
	void flushTypeList();
    
	
private:
	//Symbol table
	SymbolTable symbolTable;
	//Function table
	FunctionTable functionTable;
	//Current list of variables whose allocation is deferred.
	queue<string> currVarList;
	//Current list of variables whose allocation is deferred.
	queue<TypesP> currTypeList;
	
	string popVar(void);
	TypesP popType(void);
	void concVarList(queue<string> first,queue<string> second);
	void concTypeList(queue<TypesP> first,queue<TypesP> second);
	
};
#endif